from tortoise.signals import post_save
from blog.models import Comment, Notification


@post_save(Comment)
async def create_notification(*args):
    # args = (<class 'blog.models.Comment'>, <Comment: 18>, True, 
    # <tortoise.backends.asyncpg.client.AsyncpgDBClient object at 0x0000028E9CEB5D30>, None)
    comment = args[1]
    if comment.owner != "admin":
        # create notifications here, or use a task queue
        await Notification.create(article_id=comment.article_id, comment_id=comment.id)